-
Notifications
You must be signed in to change notification settings - Fork 117
[Woo POS] Coupons: Disallow adding duplicate coupons to cart #15551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Woo POS] Coupons: Disallow adding duplicate coupons to cart #15551
Conversation
We cannot extract the function to make SUT for the whole test suite (at least not straight-away) as crashes due analytics running on different threads that we expect for each enum in the test suite.
Despite disallowing for duplicated coupons to be added to cart, the action handler is generic to all items so we were still calling the tracking event. We create a handler specifically for coupons to avoid calling the event when it shouldnt
|
@iamgabrielma thanks for the work! Let's wait before merging until we get input from design. I think it's better right now to show an error in the checkout rather than not allow tapping the item without any visual signal. Also, let's clarify if the item should be tappable when it's disabled (including the expired one). Maybe we wouldn't need a separate item handler logic. Thanks! |
Confirmed with design FnDpCHVQ3Zpefad04ptbd4-fi-node-id=419-79264#1230020091 that nothing should happen when attempting to add a duplicated coupon to the cart. Will resolve the merge conflicts EOD and re-submit 👍 |
Version |
…-twice # Conflicts: # WooCommerce/Classes/POS/Presentation/ItemListView.swift # WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift
Not that reusable, as analytics is not thread safe and crashes randomly some tests. For now let’s declare the dependencies per test basis
@iamgabrielma to confirm, is it ready for review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just remove the unused code 👍
@@ -51,6 +51,28 @@ final class StandardPOSItemActionHandler: POSItemActionHandler { | |||
} | |||
} | |||
|
|||
@available(iOS 17.0, *) | |||
final class CouponsItemActionHandler: POSItemActionHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed, can be removed 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't see that we stopped using CouponsItemActionHandler
since I worked on this bit. Removing it introduces a regression thought, as we treat products and coupons equally when dealing with track events, meaning: We will track the add_to_cart
event despite coupons not being added to cart when are duplicated:
🔵 Tracked pos_coupon_added_to_cart, properties: [site_url: https://indiemelon.mystagingwebsite.com, blog_id: -1, was_ecommerce_trial: false, plan: , store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, is_wpcom_store: false]
🔵 Tracked pos_coupon_added_to_cart, properties: [store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, plan: , is_wpcom_store: false, blog_id: -1, was_ecommerce_trial: false, site_url: https://indiemelon.mystagingwebsite.com]
I've added a small helper function to handle this case in POSItemActionHandler
, as this will happen both when we add coupons via list and via search.
I'll leave this one without merging for now in case you want to take a look, in a nutshell when adding coupons from either list or search, the track event should be logged just once.
Yes! Sorry I wasn't clear 🙇 |
Since the specific CouponsItemActionHandler is not used anymore, we still need to deal with duplicates coupons in the general handler to avoid duplicated track events
@@ -49,7 +49,9 @@ extension Cart { | |||
case .variableParentProduct: | |||
return | |||
case .coupon(let coupon): | |||
let couponItem = Cart.CouponItem(id: UUID(), code: coupon.code, summary: coupon.summary) | |||
guard !coupons.contains(where: { $0.id == coupon.id }) else { return } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this check here if we skip the duplicate in the action handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
Partially addresses WOOMOB-259 by disallowing duplicated coupons to be added to the cart, while we get feedback from design on how to handle it UI-wise.
We also avoid calling the
pos_coupon_added_to_cart
track event multiple times by creating a new implementation forPOSItemActionHandler
, otherwise we could see the track event called multiple times despite the action being disallowed, as we used the same action handler across products and coupons:Testing information
pos_coupon_added_to_cart
event is only logged once, when we add the coupon to the cartScreenshots
Screen.Recording.2025-04-25.at.10.34.12.mov
Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: